package com.Factory;

import com.Result.ChatRecordResult;
import com.entity.ChatRecord;
import com.entity.User;
import com.mapper.UserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class CharRecordFactory {
    @Autowired
    private UserMapper userMapper;

    public ChatRecordResult newChatRecordResult(ChatRecord chatRecord) {
        ChatRecordResult chatRecordResult = new ChatRecordResult();
        BeanUtils.copyProperties(chatRecord, chatRecordResult);
        User user = this.userMapper.selectById(chatRecord.getSendUserId());
        chatRecordResult.setSendUserHeadURL(user.getHeadShotUrl());
        chatRecordResult.setSendUserName(user.getName());
        return chatRecordResult;
    }

    public List<ChatRecordResult> getChatRecordResult(List<ChatRecord> chatRecordList) {
        List<ChatRecordResult> urlList = new ArrayList<>();
        for(ChatRecord chatRecord : chatRecordList) {
            urlList.add(this.newChatRecordResult(chatRecord));
        }
        return urlList;
    }
}
